import torch

class ModelUtil:
    @staticmethod
    def save_model(model, db_name, filename=None):
        if filename is None:
            filename = f'saved/{db_name}.pt'
        
        torch.save({'model': model.state_dict()}, filename)

    @staticmethod
    def load_model(model, db_name, filename=None):
        if filename is None:
            filename = f'saved/{db_name}.pt'

        try:
            state_dict = torch.load(filename)
            model.load_state_dict(state_dict['model'])
        except:
            pass